SHELL=sh
RM=rm -f
CD=cd
#Define the cross complier
CROSS_COMPILER=arm-elf-
CC=$(CROSS_COMPILER)gcc
CPP=$(CROSS_COMPILER)g++
LD=$(CROSS_COMPILER)ld
OBJCOPY=$(CROSS_COMPILER)objcopy
OBJDUMP=$(CROSS_COMPILER)objdump
OBJNM=$(CROSS_COMPILER)nm
OBJSIZE=$(CROSS_COMPILER)OBJSIZE

#Define C flags
CFLAGS=-g -c -mcpu=arm920t 
CFLAGS+=-Iinc -I libmad  -elf2flt
CFLAGS+=-fno-builtin
CFLAGS+=-Wall -Wstrict-prototypes
CFLAGS+=-Wmissing-declarations -Wmissing-prototypes
CFLAGS+=-Wnested-externs
#Define assembly flags
ASFLAGS=-g -c -mcpu=arm920t -Iinc -Imadlib
#Define C++ flags
CPPFLAGS=
#Define LD flags
LDFLAGS= -T ram.ld
#LDFLAGS= -T ram.ld
TARGET=target
BD=bd
#Define the object files
OBJS= $(BD)/main.o $(BD)/uart.o $(BD)/start.o $(BD)/syscall.o
OBJS+=	$(BD)/bit.o 
OBJS+=$(BD)/decoder.o
OBJS+= $(BD)/fixed.o 
OBJS+=	$(BD)/frame.o 
OBJS+= $(BD)/huffman.o 
OBJS+= $(BD)/layer12.o 
OBJS+=$(BD)/layer3.o 
OBJS+=$(BD)/stream.o 
OBJS+=$(BD)/synth.o 
OBJS+=$(BD)/timer.o 
OBJS+=$(BD)/version.o 
LIB = "F:\cygwin\yagarto\arm-elf\lib\libgloss-linux.a"
LIB += "F:\cygwin\yagarto\lib\gcc\arm-elf\4.3.3\libgcc.a"
LIB += "F:\cygwin\yagarto\lib\gcc\arm-elf\4.3.3\libgcov.a"
LIB += "F:\cygwin\yagarto\arm-elf\lib\libg.a"
LIB += "F:\cygwin\yagarto\arm-elf\lib\libc.a"
LIB += "F:\cygwin\yagarto\arm-elf\lib\libm.a"
LIB += "F:\cygwin\yagarto\arm-elf\lib\libiberty.a"
LIB += "F:\cygwin\yagarto\arm-elf\lib\libnosys.a"
LIB += "F:\cygwin\yagarto\arm-elf\lib\librdimon.a"
LIB += "F:\cygwin\yagarto\arm-elf\lib\librdpmon.a"
LIB += "F:\cygwin\yagarto\arm-elf\lib\libstdc++.a"
LIB += "F:\cygwin\yagarto\arm-elf\lib\libsupc++.a"

#LIB += mp3dec.a
$(BD)/$(TARGET).bin:$(OBJS)
	@echo
	@echo linking...
	$(LD) $(LDFLAGS)      -o $(BD)/$(TARGET).elf $(OBJS) $(LIB)

	@echo
	@echo Creating binary file for download...
	$(OBJCOPY) -O binary $(BD)/$(TARGET).elf $(BD)/$(TARGET).bin

	@echo
	@echo dumping the elf file...
	$(OBJDUMP) -S $(BD)/$(TARGET).elf > $(BD)/$(TARGET).lst

	@echo
	@echo Creating the symbol table...
	$(OBJNM) -a $(BD)/$(TARGET).elf > $(BD)/$(TARGET).sym

	

DEBUG:
	#openocd-ftd2xx -f openocd.cfg
	#cd $(BD);	arm-elf-insight  -x=gdbsript.txt

	arm-elf-insight  -x=gdbsript.txt
	//arm-elf-insight -x=gdbsim

vpath %.S src
vpath %.c src
vpath %.c libmad
vpath %.h libmad

$(BD)/%.o:%.c
	@echo
	@echo Compiling $<...
	$(CC) $(CFLAGS)  $< -o $@
$(BD)/%.o:%.S
	@echo
	@echo Assembling $<...
	$(CC) $(ASFLAGS) $< -o $@

clean:
	@echo
	@echo cleaning files
	$(RM) *.o *.elf *.lst *.bin *.sym
	$(CD) $(BD);$(RM) *.o *.elf *.lst *.bin *.sym

.PHONY: clean all







